/**
 * admin888 <doan.hut@gmail.com>
 * @autho : Nguyễn tiến Pa Ven 
 * Thao tác cho thu nháp 
 */
function xoafileandb(linkfile,idfle){
	var idrm = "#filechek_"+idfle;
	var tongfile = document.getElementById('tong_file').value;
	var idthu = document.getElementById('idthunhap').value;
	var url = document.getElementById('url').value
	var link = url+"/thunhap/xoafiledinhkem/idflie/"+idfle+"/tongfile/"+tongfile+"/idthu/"+idthu;
	var tongfile = document.getElementById('tong_file').value * 1 - 1;
    $("#tong_file").val(tongfile);
	$(idrm).remove();
	$.ajax({
		type:"GET",
		url: link,
		
	});
}
function uploadfilenhapsua(){
    $(function(){
        var url = document.getElementById('url').value;
        var link = url + '/upload/';
        var linthumhinh = link + '/uploads/';
        var btnUpload = $('#upload');
        var status = $('#status');
        loading();
        new AjaxUpload(btnUpload, {
            //action: link + 'upload.php',
			action: url+'/ajax/uploadfile/',
            name: 'uploadfile',
            onSubmit: function(file, ext){
				$('#status').show();
            },
            onComplete: function(file, response){
                //On completion clear the status
				$('#status').hide();
                //Add uploaded file to list
                var tongfile = document.getElementById('tong_file').value * 1 + 1;
                $("#tong_file").val(tongfile);
                if (response === "success") {
                    var linkhinhchuan =  "upload/uploads/" + file;
					//add file to db
					var idtnh = document.getElementById('idthunhap').value;
					var linkupldb = url+"/thunhap/addfilethunhapdb/tongfile/"+tongfile+"/idthunhap/"+idtnh+"?hinh="+linkhinhchuan;
					$.ajax({
						type:"GET",
						url: linkupldb,
						success:function(data){					
		                    var tenhinh = '<li id=\"filechek_' + data + '\">' +
		                    '<input type=\"checkbox\" checked=\"checked\" onclick=\"xoafileandb(\'' + linkhinhchuan +'\',\'' +data +'\');\" id=\"filechek_' +tongfile +'\" name=\"file[]\" value=\"' +linkhinhchuan +'\" />' +
		                    //'<a href=\"' +linkhinhchuan +'\" target=\"_blank\">' +file +'</a>' +
							file+
		                    '</li>';
		                    $('#files').append(tenhinh);
						}
					});	
									
                }
                else {
                    $('<li></li>').appendTo('#files').text(file).addClass('error');
                }
            }
        });
        stoploading();
        
    });
    
}